fix: ignore double colon cast operators in SQL parameter substitution - #3414
Merged
Conversation
kukushking
approved these changes
Jul 31, 2026
Collaborator
|
Thanks @hsusul ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes an issue in
awswrangler._sql_formatter._process_sql_paramswhere double-colon type cast operators (e.g.col::text,col::timestamp,col::varchar,col::integer) are mistakenly parsed as parameter placeholders when a parameter name matches the cast target type name.Root Cause
The parameter substitution regex
_PATTERNwas defined asre.compile(r":([A-Za-z0-9_]+)(?![A-Za-z0-9_])"). When a SQL query contains double colons::(standard ANSI / PostgreSQL / Athena / Presto / Trino / CleanRooms cast syntax), the second colon was matched as a parameter placeholder. Ifparamscontained a key matching the type name (such astextincol::text),_process_sql_paramssubstituted the cast operator, corrupting the SQL query tocol:'value'and causing runtime SQL syntax errors.Solution
Updated
_PATTERNinawswrangler/_sql_formatter.pywith a negative lookbehind(?<!:)to ensure single-colon parameters (e.g.,:id) are matched without matching double-colon cast operators (::type):Validation & Testing
test_process_sql_params_double_colon_castintests/unit/test_sql_params_formatter.pyasserting that double-colon type casts are preserved while parameter placeholders are correctly substituted.upstream/mainbaseline before applying fix.pytest tests/unit/test_sql_params_formatter.py(Passed 13/13)ruff format --check .(Passed)ruff check .(Passed)mypy awswrangler/_sql_formatter.py tests/unit/test_sql_params_formatter.py(Success)git diff --check(Clean)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.